<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>工单添加服务计划</title>
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <style type="text/css">
        .detail {
            padding-right: 20px!important;
        }

        h5,
        label {
            color: #0062CC;
        }

        label {
            font-size: 14px;
        }

        .mui-navigate-right .mui-col-xs-8 {
            width: 62.666667%!important;
        }

        .mui-text-right input,
        .mui-text-right textarea {
            border: 0;
            font-size: 14px;
            font-weight: 400;
            color: #8f8f94;
            margin-bottom: 0;
            text-align: right;
        }
    </style>
</head>

<body>
    <div class="mui-content">
        <ul class="mui-table-view mui-table-view-chevron type_list_spair">
            <li class="mui-table-view-cell detail" tapmode onclick="openSaveWin('work_order_sel_tast','选择任务',{wonum: api.pageParam.wonum,linetype: api.pageParam.linetype})">
                <div class="mui-table mui-navigate-right">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">任务：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="tastnum">请选择任务</span>
                    </div>
                </div>
            </li>
            <li class="mui-table-view-cell detail" tapmode onclick="openSaveWin('work_order_sel_server','选择服务')">
                <div class="mui-table mui-navigate-right">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">服务：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="server">请选择服务</span>
                    </div>
                </div>
            </li>
            <li class="mui-table-view-cell detail">
                <div class="mui-table">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">描述：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="serverdesc"></span>
                    </div>
                </div>
            </li>
            <li class="mui-table-view-cell detail">
                <div class="mui-table">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">数量：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <input type="number" onchange="linecost()" placeholder="请输入数量" name="" id="itemqty" value="" />
                    </div>
                </div>
            </li>
            <li class="mui-table-view-cell detail">
                <div class="mui-table">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">单位成本：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <input type="number" onchange="linecost()" placeholder="请输入单位成本" name="" id="unitcost" value="" />
                    </div>
                </div>
            </li>
            <li class="mui-table-view-cell detail">
                <div class="mui-table">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">行成本：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="lineText">0.00</span>
                    </div>
                </div>
            </li>
        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script src="../script/mui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../script/common.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    var itemqty = '',
        wonum = '',
        unitcost = '',
        linecost = '',
        taskduration = '';
        itemnum = '';
    apiready = function() {
//      LoadDetail();
        api.addEventListener({
            name: 'TastId'
        }, function(ret, err) {
            wonum = ret.value.tastnum;
            $api.html($api.byId('tastnum'), ret.value.description)
        });
        api.addEventListener({
            name: 'server'
        }, function(ret, err) {
            itemnum = ret.value.itemnum;
            $api.html($api.byId('server'), ret.value.itemnum)
            $api.html($api.byId('serverdesc'), ret.value.description)
        });
        api.addEventListener({
            name: 'navitembtn'
        }, function(ret, err) {
            if (ret.index == 0) {
                if ($api.html($api.byId('tastnum')) == '请选择任务') {
                    Toast('请选择任务！');
                    return
                }
                if ($api.html($api.byId('server')) == '请选择服务') {
                    Toast('请选择服务！');
                    return
                }
                if ($api.val($api.byId('itemqty')) == '') {
                    Toast('请填写数量！');
                    return
                }
                if ($api.val($api.byId('unitcost')) == '') {
                    Toast('请填写单位成本！');
                    return
                }
                if (api.pageParam.add == 'actual') {
                    ajaxrd("saveServiceTrans", { //添加实际
                        refwo: wonum,
                        quantity: $api.val($api.byId('itemqty')),
                        unitcost: $api.val($api.byId('unitcost')),
                        linecost: $api.text($api.byId('lineText')),
                        itemnum: itemnum
                    }, function(ret, err) {
                        api.sendEvent({
                            name: 'refersh',
                            extra: {
                                isrefersh: 'yes'
                            }
                        });
                        Toast('新增成功！');
                        setTimeout(function() {
                            api.closeWin();
                        }, 500)
                    })
                } else {
                    ajaxrd("savePlanService", { //添加计划
                        wonum: wonum,
                        itemqty: $api.val($api.byId('itemqty')),
                        unitcost: $api.val($api.byId('unitcost')),
                        linecost: $api.text($api.byId('lineText')),
                        itemnum: itemnum
                    }, function(ret, err) {
                        api.sendEvent({
                            name: 'refersh',
                            extra: {
                                isrefersh: 'yes'
                            }
                        });
                        Toast('新增成功！');
                        setTimeout(function() {
                            api.closeWin();
                        }, 500)
                    })
                }

            } else { //扫码

            }
        });
    }
    var linecost = function() {
        if ($api.val($api.byId('itemqty')) == '' || $api.val($api.byId('unitcost')) == '') {
            return
        }
        $api.text($api.byId('lineText'), $api.val($api.byId('itemqty')) * $api.val($api.byId('unitcost')))
    }
//  function LoadDetail() {
//      ajaxrd("queryPlanServiceDetail", {
//          wpitemid:api.pageParam.wpitemid
//      }, function(ret, err) {
//          $api.html($api.byId('tastnum'), ret.wonum);
//          wonum = ret.wonum;
//          $api.html($api.byId('server'), ret.itemnum);
//          $api.html($api.byId('serverdesc'), ret.description);
//          itemnum = ret.itemnum
//          $api.val($api.byId('itemqty'), ret.itemqty);
//          $api.val($api.byId('unitcost'), ret.unitcost);
//          $api.text($api.byId('lineText'), ret.linecost)
//      })
//    }
</script>

</html>
